import Mock from "mockjs"
import { builder, getBody } from "../utils"
let dataList = []
for (let i = 0; i < 33; i++) {
	let obj = {
		id: i + 1,
		sort: i + 1,
		title: "标题" + (i + 1),
		content: Mock.mock(
			`@pick(["这是功能型表格的演示内容，这是第${i + 1}行内容","这是第${
				i + 1
			}行内容","演示内容${i + 1}","这是功能型表格的第${i + 1}行内容"])`
		),
		createdTime: Mock.mock("@datetime('yyyy/MM/dd HH:mm:ss')"),
	}
	dataList.push(obj)
}
const searchTable = (options) => {
	const body = getBody(options)
	let data = {
		total: 0,
		content: [],
	}
	data.content = dataList
	if (body) {
		if (body.query) {
			data.content = data.content.filter((item) =>
				item.title.includes(body.query)
			)
		}
		if (body.title) {
			data.content = data.content.filter(
				(item) => item.title === body.title
			)
		}
		data.total = data.content.length
		data.content = data.content.slice(
			(body.current - 1) * body.pageSize,
			body.current * body.pageSize
		)
		data.current = body.current
		data.pageSize = body.pageSize
	}
	return builder(data)
}
const baseTable = (options) => {
	let data = []
	const templete = {
		name: "@ctitle(1,3)",
		content: "@ctitle(2)",
	}
	for (let i = 0; i < 11; i++) {
		data.push(Mock.mock(templete))
	}
	return builder(data)
}
export default {
	"post|/searchTable/getSearchTable": searchTable,
	"get|/baseTable/getBaseTable": baseTable,
}
